<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
     <a-form ref="formRef" :model="formState" layout="vertical" :rules="ESSAY_EDIT.RULES">
      <a-row :gutter="12">

        <a-col :span="24">
          <a-form-item label="文章标题" field="title">
            <a-input v-model="formState.title" allow-clear placeholder="请填文章标题"/>
          </a-form-item>
        </a-col>
        <a-col :span="24">
        <a-form-item label="阅读群体" field="scope">
          <smart-dict :url="DictOptions.NoticeScope" v-model="formState.scope" is-radio :disabled="isUpdate"/>
        </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="文章摘要" field="digest">
            <a-textarea :auto-size="{minRows:2,maxRows:5}" :max-length="200" v-model="formState.digest"
                       placeholder="请填文章摘要"/>
          </a-form-item>
        </a-col>


        <a-col :span="24">
          <a-form-item label="文章正文" field="content">
              <smart-rich-editor  v-model="formState.content" />
          </a-form-item>
        </a-col>
      </a-row>


    </a-form>
    <!--表单结束-->
  </a-drawer>
</template>

<script lang="ts" setup>

import {EditDrawer} from '@/libs/core'

import {ESSAY_EDIT} from "../resource/form";
import {SystemHttp} from '../resource/http'
import {DictOptions} from "@/libs/options";

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])

const {addEssay, updateEssay} = SystemHttp
const config = {tplRecord: ESSAY_EDIT.BODY, rawRecord: props.record, rowKey: 'id', emit}

const service = new EditDrawer(config).setAddRequest(addEssay).setUpdateRequest(updateEssay)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改品牌文章' : '新建品牌文章'
</script>
